<?php
namespace Home\Controller;
class CateController extends CommonController {

	public function _initialize()
	{
		$this->Is_login();        //检测用户登录信息,如果错误直接返回错误,终止程序
		$this->assign('heardadminData',session('heardadminData'));
	}


	//标签列表
	public function cate_list()
	{
		$db_bgm = M("bgm");
		$catelist = $db_bgm->order('sortid asc')->select();
		// p($catelist);exit();
		$this->assign('catelist',$catelist);
		$this->display();

	}
	public function cate_ajax(){
		// p($_POST);exit();
		$id = I('post.id');
		$order = I('post.order');
		$db_bgm = M("bgm");
		$catelist = $db_bgm->order('sortid asc')->select();
		$o_arr = explode(",", $id);
		if (count($catelist) == count($o_arr)) {
			foreach ($o_arr as $key => $value) {
				$data['sortid'] = $key+1;
				$db_bgm->where(array('id'=>$value))->save($data);
			}
			exit("100");
		}else{
			exit("001");
		}

	}
	//创建标签
	public function cate_add()
	{
		$this->display();
	}
	public function add_cate()
	{
		$catename = I('post.catename');
		if (empty($catename)) {
			$this->error('参数错误',"",1);
		}
		$db_mediacate = D("mediacate");
		if (!$db_mediacate->create()){//自动验证
			$this->error('参数错误',"",1);
		}else{
			$data = $db_mediacate->create(); // 保存生成的数据对象

			$data['addtime'] = date('Y-m-d H:i:s',time());
			$data['catename'] = $catename;
			// p($data);exit();
			$result = $db_mediacate->add($data);
			$cid['sortid'] = (int)$result;
			$db_mediacate->where(array('id'=>$result))->save($cid);
			$this->success('创建成功',"/Home/Cate/cate_add",1);
		}
	}


	//修改标签
	public function cate_edit()
	{
		$id = I('get.id');

		// p($catedata);exit();
		$this->assign('catedata',$catedata);
		$this->display();
	}

	public function edit_cate()
	{
		$id = I('post.id');

		$this->success('修改成功',"/Home/Cate/cate_list",1);

	}
}